<?php
header("Content-Type: text/html; charset=utf-8");
include_once 'menu.php';

$action=$_GET['action'];
if($action=="edit"){
	$parentId=$_POST["parentId"];
	$menuName=$_POST["menuName"];
	$menuUrl=$_POST["menuUrl"];
	$catId=$_POST["proId"];
	$ret=menu_update($catId,$parentId,$menuName,$menuUrl);
	
	if($ret!=true){
		echo "<script>alert('编辑失败！');</script>";	
	}else{
		echo "<script>alert('编辑成功！');</script>";	
	}
	echo ("<script>document.location='menuCatalog.php';</script>");	
}else{
	$id= intval($_GET['id']);
	$catList=get_menu_list_by_id($id);
	$catListAll=list_menu();
	if($catList!=false){
		$catItem=$catList[0];		
	}else{
		 
		die("错误的Id");
	}
}

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>菜单分类编辑</title>
<link rel="stylesheet" type="text/css" href="../skin/css/base.css">
<style type="text/css">
.catLog{margin: 20px; padding-top:5px;}
.catLog select { width:300px; }
.catLog input.txtInput{width:300px; }
.catLog input.btSubmit{ margin-left:170px; margin-top:6px;}
</style>
</head>
<body leftmargin="8" topmargin="8" background='../skin/images/allbg.gif'>
<form action="menuEdit.php?action=edit" method="post">
<div class="catLog" >
	菜单名称:&nbsp;<input id="menuName" name="menuName"  class="txtInput" value="<?=$catItem->menu_name?>" 
	/><br />
	菜单Url:&nbsp;&nbsp;&nbsp;&nbsp;<input id="menuUrl" name="menuUrl"  class="txtInput" value="<?=$catItem->menu_url?>" 
	/><br />
	所属父类:&nbsp;<select id="parentId" name="parentId">
		<option value="0">无父类</option>
		<?php 
		foreach ($catListAll as $item) {
			$selected="";
			if($item->id !=$id){
				if($item->id==$catItem->menu_parent_id  ){
					$selected="selected=\"selected\"";
				}
			?>
				<option   <?=$selected?>   $selected value="<?=$item->id ?>"><?=$item->menu_name ?></option>
		 	<?php  
 			}
		}		
		?>
	</select><br />
<input type="submit" class="btSubmit" value="提交" /> <br />
<input type="hidden" value="<?=$_GET["id"]?>" name="proId" id="proId" />
</div>
</form>
</body>
</html>
